﻿<Window
   x:Class="MVVM_Wrapper_Test.Window1"
   x:Name="window"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1"
   Background="#FFF4F4F4"
   Height="300"
   Width="600">
   <Grid
      Margin="10,10,10,10">
      <Grid.RowDefinitions>
         <RowDefinition
            Height="*" />
         <RowDefinition 
            Height="30" />
         <RowDefinition
            Height="Auto" />
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
         <ColumnDefinition
            Width="*" />
         <ColumnDefinition
            Width="10" />
         <ColumnDefinition
            Width="*" />
      </Grid.ColumnDefinitions>

      
      <DockPanel
         Grid.Column="0">
         <TextBlock
            DockPanel.Dock="Top"
            FontWeight="Bold"
            Foreground="Blue"
            Text="View Model" />
      
         <ListView
            x:Name="listViewViewModel"
            ItemsSource="{Binding ElementName=window, Path=PersonViewModelCollection}">
            <ListView.View>
               <GridView>
                  <GridViewColumn
                     Header="Name"
                     Width="80"
                     DisplayMemberBinding="{Binding Path=Name}" />
                  <GridViewColumn
                     Header="Age"
                     Width="50"
                     DisplayMemberBinding="{Binding Path=Age}" />
               </GridView>
            </ListView.View>
         </ListView>
      </DockPanel>

      <StackPanel
         Orientation="Horizontal"
         Grid.Row="1"
         Grid.Column="0">
         <TextBlock
            Text="Name"
            Margin="0,0,8,0"
            VerticalAlignment="Center"
            FontWeight="Bold"
            Foreground="Blue" />
         <TextBox
            Text="{Binding ElementName=listViewViewModel, Path=SelectedItem.Name, UpdateSourceTrigger=PropertyChanged}"
            Width="50"
            Margin="0,0,18,0"
            VerticalAlignment="Center" />
         <TextBlock
            Text="Age"
            Margin="0,0,8,0"
            VerticalAlignment="Center"
            FontWeight="Bold"
            Foreground="Blue" />
         <TextBox
            Text="{Binding ElementName=listViewViewModel, Path=SelectedItem.Age, UpdateSourceTrigger=PropertyChanged}"
            Width="50"
            VerticalAlignment="Center" />         
      </StackPanel>

      <DockPanel
         Grid.Column="2">
         <TextBlock
            DockPanel.Dock="Top"
            Text="Business Object"
            Foreground="DarkViolet"
            FontWeight="Bold" />      
         <ListView
            x:Name="listViewBusiness"
            ItemsSource="{Binding ElementName=window, Path=PersonCollection}">
            <ListView.View>
               <GridView>
                  <GridViewColumn
                     Header="Name"
                     Width="80"
                     DisplayMemberBinding="{Binding Path=Name}" />
                  <GridViewColumn
                     Header="Age"
                     Width="50"
                     DisplayMemberBinding="{Binding Path=Age}" />
               </GridView>
            </ListView.View>
         </ListView>
      </DockPanel>


      <StackPanel
         Orientation="Horizontal"
         Grid.Row="1"
         Grid.Column="2">
         <TextBlock
            Text="Name"
            Margin="0,0,8,0"
            VerticalAlignment="Center"
            FontWeight="Bold"
            Foreground="DarkViolet" />
         <TextBox
            Text="{Binding ElementName=listViewBusiness, Path=SelectedItem.Name, UpdateSourceTrigger=PropertyChanged}"
            Width="50"
            Margin="0,0,18,0"
            VerticalAlignment="Center" />
         <TextBlock
            Text="Age"
            Margin="0,0,8,0"
            VerticalAlignment="Center"
            FontWeight="Bold"
            Foreground="DarkViolet" />
         <TextBox
            Text="{Binding ElementName=listViewBusiness, Path=SelectedItem.Age, UpdateSourceTrigger=PropertyChanged}"
            Width="50"
            VerticalAlignment="Center" />         
      </StackPanel>

      <StackPanel
         Orientation="Horizontal"
         Grid.Row="2"
         Margin="0,10,0,0">
         <Button
            x:Name="addPersonToUnderlyingCollection"
            Click="addPersonToUnderlyingCollection_Click"
            VerticalAlignment="Center"
            Width="80"
            Margin="0,0,8,0">Add</Button>
         <Button
            x:Name="removePersonFromUnderlyingCollection"
            Click="removePersonFromUnderlyingCollection_Click"
            VerticalAlignment="Center"
            Width="80">Remove</Button>
      </StackPanel>
   </Grid>
</Window>
